/* Keytable data type
*
* by Twilight Suzuka + Kuchiki Rukia + Urahara Kisuke
* 
*
* This file is provided as is (no warranties).
*/
// Keytables are reliable methods of mapping strings to values.
// While not as fast as hashtables, they are much more reliable. Searching is much faster as well.
// Keytables are your best bet for general purpose vault-like usage.

#if defined _array_keytable_included
    #endinput
#endif
#define _array_keytable_included

#include <array_const>

///* Master Edit Functions

// Creates a new keytable
native keytable_create()

// Destroys a created keytable, and sets the pointer back to NULL. You MUST destroy all keytable's you create.
native keytable_destroy(&keytable_id)

// Clears a keytable without deleting it
native keytable_clear(keytable_id)

// If keytable_id = 0, returns the keytable master table, which can be manipulated as an array.
// Else, returns the keytable's master table keytable_id.
native keytable_convert(keytable_id=0)

// Saves/loads keytables from file. keytable_id must be to an already created keytable.
native keytable_save(keytable_id,file[])
native keytable_load(keytable_id,file[])

///* Master Amount Functions

// Counts the amount of keytables in the master table.
native keytable_count(start = 0, stop = -1)

// Returns the nth keytable in the master table, into ret_array. Return value is its master table keytable_id.
native keytable_bycount(nth, start = 0, &ret_array = 0)

///* Slave Amount Functions

// Returns how many indexes are in the keytable
native keytable_size(keytable_id, start[] = "", stop[] = "~~~~~~~~~~~")

// Returns the nth index in the keytable. 
// NOTE: Pass a variable to hold the index[], and its length, after success. 
// Length is 1 for bool/int/flo, 3 for vec, x for string.
native keytable_get_nth(keytable_id, nth, start[] = "",&success = 0,{Float,Sql,Result,_}:...)

///* Slave Edit Functions

// Returns the amount of memory this keytable has used
native keytable_memory(keytable_id)

// Returns if index is used or not.
native keytable_isfilled(keytable_id, index[])
native keytable_isempty(keytable_id, index[])

///* Slave Set/Get/Delete Functions
// These don't need explaining.

// Gets the type of value stored in index. Uses pawn_type_* enum, see array_const for details.
native keytable_get_type(id, index, disable_check = 0)

// Deletes an index from keytable
native keytable_delete(keytable_id, index)

// set_type is from AP_* list in array_const
native keytable_set(keytable_id, index[], set_type,{Float,Sql,Result,_}:...)

// get format is [ret_val,len]. See array_const for details.
native keytable_get(keytable_id, index[], disable_check = 0,{Float,Sql,Result,_}:...)

native keytable_set_bool(keytable_id, index[], bool:set_bool)
native bool:keytable_get_bool(keytable_id, index[], disable_check = 0)

native keytable_set_int(keytable_id, index[], set_int)
native keytable_get_int(keytable_id, index[], disable_check = 0)

native keytable_set_float(keytable_id, index[], Float:set_flo)
native Float:keytable_get_float(keytable_id, index[], disable_check = 0)

native keytable_set_string(keytable_id, index[], set_str[])
native keytable_get_string(keytable_id, index[], val[], len, disable_check = 0)

native keytable_set_vector(keytable_id, index[], Float:set_vec[3])
native keytable_get_vector(keytable_id, index[], Float:val[3], disable_check = 0)

///* Slave Search Functions
// NOTE: Pass a variable to hold the index, and its length, after success. 
// Length is 1 for bool/int/flo, 3 for vec, x for string.
// If you do not wish to recieve the index, do not pass anything past success.

// Finds the first filled index starting at provkeytable_ided index, returns its key into ret[].
native keytable_first(keytable_id, index[], ret[], len, &success = 0,{Float,Sql,Result,_}:...)

// Finds the filled index after provkeytable_ided index, returns its key into ret[].
native keytable_next(keytable_id, index[], ret[], len, &success = 0,{Float,Sql,Result,_}:...)

// Finds the filled index before provkeytable_ided index, returns its key into ret[].
native keytable_prev(keytable_id, index[], ret[], len, &success = 0,{Float,Sql,Result,_}:...)

// Finds the last filled index starting at provkeytable_ided index, returns its key into ret[].
native keytable_last(keytable_id, index[], ret[], len, &success = 0,{Float,Sql,Result,_}:...)

#include <keytable_stocks>
